using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.physx
{
[System.Serializable]
public  class Collider :   cfg.EditorReadWriter 
 {

    public bool isTrigger ;
     public cfg.map.Vector3 position  = new cfg.map.Vector3();
     public cfg.map.Vector3 rotation  = new cfg.map.Vector3();
     public cfg.map.Vector3 scale  = new cfg.map.Vector3();
     public cfg.physx.Material material ;
     public cfg.physx.Geometry geometry ;
     


    public const int TYPE_ID = 1343653926;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(6);
        os.WriteSize(Tag.BOOL | (1 << Tag.TAG_SHIFT));  os.WriteBool(isTrigger);  
         os.WriteSize(Tag.BEAN | (2 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_map_Vector3(position,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.BEAN | (3 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_map_Vector3(rotation,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.BEAN | (4 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_map_Vector3(scale,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.BEAN | (6 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_physx_Material(material,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.BEAN | (5 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_physx_Geometry(geometry,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.BOOL | (1 << Tag.TAG_SHIFT)):   isTrigger = os.ReadBool(); break;  
             case (Tag.BEAN | (2 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); position = cfg.Extensions.unmarshal_compatible_cfg_map_Vector3(os); os = _oldOs; break; }   
             case (Tag.BEAN | (3 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); rotation = cfg.Extensions.unmarshal_compatible_cfg_map_Vector3(os); os = _oldOs; break; }   
             case (Tag.BEAN | (4 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); scale = cfg.Extensions.unmarshal_compatible_cfg_map_Vector3(os); os = _oldOs; break; }   
             case (Tag.BEAN | (6 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); material = cfg.Extensions.unmarshal_compatible_cfg_physx_Material(os); os = _oldOs; break; }   
             case (Tag.BEAN | (5 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); geometry = cfg.Extensions.unmarshal_compatible_cfg_physx_Geometry(os); os = _oldOs; break; }   
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "Collider");
        ele.WriteStartElement("isTrigger"); ele.WriteAttributeString("id", "1"); ele.WriteBool(isTrigger); ele.WriteEndElement();
         ele.WriteStartElement("position"); ele.WriteAttributeString("id", "2"); cfg.Extensions.xml_marshal_cfg_map_Vector3(position,ele); ele.WriteEndElement();
         ele.WriteStartElement("rotation"); ele.WriteAttributeString("id", "3"); cfg.Extensions.xml_marshal_cfg_map_Vector3(rotation,ele); ele.WriteEndElement();
         ele.WriteStartElement("scale"); ele.WriteAttributeString("id", "4"); cfg.Extensions.xml_marshal_cfg_map_Vector3(scale,ele); ele.WriteEndElement();
         ele.WriteStartElement("material"); ele.WriteAttributeString("id", "6"); cfg.Extensions.xml_marshal_cfg_physx_Material(material,ele); ele.WriteEndElement();
         ele.WriteStartElement("geometry"); ele.WriteAttributeString("id", "5"); cfg.Extensions.xml_marshal_cfg_physx_Geometry(geometry,ele); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  isTrigger = ele.ReadBool(); break; 
                 case 2:  position = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case 3:  rotation = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case 4:  scale = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case 6:  material = cfg.Extensions.xml_unmarshal_cfg_physx_Material(ele); break; 
                 case 5:  geometry = cfg.Extensions.xml_unmarshal_cfg_physx_Geometry(ele); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "is_trigger":  isTrigger = ele.ReadBool(); break; 
                 case "position":  position = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case "rotation":  rotation = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case "scale":  scale = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case "material":  material = cfg.Extensions.xml_unmarshal_cfg_physx_Material(ele); break; 
                 case "geometry":  geometry = cfg.Extensions.xml_unmarshal_cfg_physx_Geometry(ele); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
